package com.es.www.kyl.config;

import com.es.www.kyl.bean.R;
import com.es.www.kyl.exception.ResException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice(basePackages = {"com.es.www.kyl.controller"})
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(value = ResException.class)
    @ResponseBody
    public R appResponseException(ResException e){
      log.error("ResponseException occured, reason：{}", e);
      return R.failResponse(e.getCode(), e.getMessage());
    }

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public R otherException(Exception e){
        log.error("otherException occured, reason：{}", e);
        return R.failCommonResponse();
    }
}
